package hackathon.att.atl.android.autoresponder;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {
	
	public static final String TABLE_NAME = "aardata";
	public static final String COLUMN_ID = "_id";
	public static final String COL_PHONE_NUM = "phone_num";
	public static final String COL_VOICE_MESSAGE = "vm_loc";
	public static final String COL_TEXT_MESSAGE = "txt_msg";
	public static final String COL_SEND_LOCATION_FLAG = "send_loc";
	public static final String COL_SELECTED_CONTACT = "contact_loc";
	
	public static final String DATABASE_NAME = "aardata.db";
	public static final int DATABASE_VERSION = 1;
	
	// Database creation sql statement
	private static final String DATABASE_CREATE = "create table "
      + TABLE_NAME + "(" + COLUMN_ID
      + " integer primary key autoincrement, " + COL_VOICE_MESSAGE +
      " text, " + COL_TEXT_MESSAGE + 
      " text, "+ COL_SEND_LOCATION_FLAG +
      " integer, " + COL_SELECTED_CONTACT + " text, " + COL_PHONE_NUM
      + " text not null);";

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	public DatabaseHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

//	public DatabaseHelper(Context context, String name, CursorFactory factory,
//			int version, DatabaseErrorHandler errorHandler) {
//		super(context, name, factory, version, errorHandler);
//		// TODO Auto-generated constructor stub
//	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		System.out.println("Create SQL "+DATABASE_CREATE);
		database.execSQL(DATABASE_CREATE);

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(DatabaseHelper.class.getName(),
	            "Upgrading database from version " + oldVersion + " to "
	                + newVersion + ", which will destroy all old data");
	        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
	        onCreate(db);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
